package com.example.mediaandroidjava;

import androidx.appcompat.app.AppCompatActivity;
import androidx.media3.common.C;
import androidx.media3.common.MediaItem;
import androidx.media3.common.MimeTypes;

import android.os.Bundle;

import java.util.HashMap;
import java.util.Map;

public class MediaItemActivity extends AppCompatActivity {
    String videoUri = "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4";
    String mediaId = "media_id_1";
    String myAppData = "my_app_data";
    String licenseUri = "license_uri";
    Map<String, String> header = new HashMap<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_media_item);
        ///media items
        MediaItem mediaItem = MediaItem.fromUri(videoUri);
        MediaItem mediaItemMore =
                new MediaItem.Builder().setMediaId(mediaId).setTag(myAppData).setUri(videoUri).build();
        ///处理非标准文件扩展
        MediaItem mediaItemNonStandardExtension = new MediaItem.Builder()
                .setUri(videoUri)
                .setMimeType(MimeTypes.APPLICATION_M3U8)
                .build();
        header.put("token", "access");
        MediaItem mediaItemProtectContent = new MediaItem.Builder()
                .setUri(videoUri)
                .setDrmConfiguration(
                        new MediaItem.DrmConfiguration.Builder(C.WIDEVINE_UUID)
                                .setLicenseUri(licenseUri)
                                .setMultiSession(true)
                                .setLicenseRequestHeaders(header)
                                .build()
                ).build();
    }
}